<%@page import="org.w3c.dom.Element"%>
<%@page import="org.w3c.dom.NodeList"%>
<%@page import="org.w3c.dom.Document"%>
<%@page import="javax.xml.parsers.DocumentBuilder"%>
<%@page import="javax.xml.parsers.DocumentBuilderFactory"%>
<%@page import="org.xml.sax.InputSource"%>
<%@page import="java.io.StringReader"%>
<%@page import="com.alibaba.fastjson.JSONArray"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="weaver.general.Util"%>
<%@page import="weaver.conn.RecordSet"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/mobile/plugin/westvalley/common/jsp/scriptEncoderCommon.jsp" %>
<%
String workflowId = Util.null2String(request.getParameter("workFlowId"));
String nodeId = Util.null2String(request.getParameter("nodeId"));
String scripts = "";
JSONArray arr = new JSONArray();
RecordSet rs = new RecordSet();
String sql = "select scripts from workflow_nodehtmllayout where workflowid = '"+workflowId+"' and nodeid = '"+nodeId+"'";
rs.executeSql(sql);
if(rs.next()){
	scripts = scriptDecode(Util.null2String(rs.getString("scripts")));
	int beginIndex = scripts.indexOf("<!--beginScript-->");
	int endIndex = scripts.indexOf("<!--endScript-->");
	if(beginIndex>=0 && endIndex>0){
		StringBuffer sb = new StringBuffer(scripts);
		String scriptsTag = sb.substring(beginIndex+"<!--beginScript-->".length(),endIndex);
		arr = builder(scriptsTag);
	}
}

out.print(arr.toJSONString());
%>
<%!

public JSONArray builder(String scriptsTag){
	JSONArray arr = new JSONArray();
	try{
		if( !"".equals(Util.null2String(scriptsTag)) ){
			StringReader sr = new StringReader("<root>"+scriptsTag+"</root>");
			InputSource is = new InputSource(sr); 
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
			DocumentBuilder builder = factory.newDocumentBuilder(); 
			Document doc = builder.parse(is);
			NodeList nodeList = doc.getElementsByTagName("script");
			for(int i=0;i<nodeList.getLength();i++){
				Element e = (Element)nodeList.item(i);
				JSONObject json = new JSONObject();
				json.put("src",e.getAttribute("src"));
				arr.add(json);
			}
		}
	}catch(Exception e){}
	return arr;
}

%>
